package com.centling.smartSealForPhone.fragment;

import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.widget.TitleBar;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public abstract class TitleBarFragment extends BaseFragment {
    @IntDef({View.VISIBLE, View.INVISIBLE, View.GONE})
    @Retention(RetentionPolicy.SOURCE)
    @interface Visibility {
    }

    protected final int TITLE_LEFT_ID = TitleBar.LEFT_ID;
    protected final int TITLE_RIGHT_ID = TitleBar.RIGHT_ID;
    protected final int FIRST_TITLE_RIGHT_ID = TitleBar.FIRST_RIGHT_ID;
    private TitleBar mTitleBar;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View mLayoutMain = inflater.inflate(R.layout.title_bar_content, container, false);
        LinearLayout mLayoutContent = mLayoutMain
                .findViewById(R.id.title_bar_content);
        mTitleBar = mLayoutMain.findViewById(R.id.title_bar);
        View mContent = inflater.inflate(setLayoutResource(), null);
        mLayoutContent.addView(mContent, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        return mLayoutMain;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        findViewInThisFunction(view);
    }

    public abstract int setLayoutResource();

    public abstract void findViewInThisFunction(View rootView);

    public void setTitleBarVisibility(@Visibility int visibility) {
        mTitleBar.setVisibility(visibility);
    }

    public void setTitleBarText(String title) {
        mTitleBar.setTitleBarText(title);
    }

    public void setTitleBarColor(int id) {
        mTitleBar.setTitleBarColor(ContextCompat.getColor(mContext, id));
    }

    public void setTitleBarLeft(int drawable) {
        mTitleBar.setLeftDrawable(drawable);
    }

    public void setTitleBarRight(int drawable) {
        mTitleBar.setRightDrawable(drawable);
    }

    public void setTitleBarLeft(String leftText) {
        mTitleBar.setLeftText(leftText);
    }

    public void setTitleBarRight(String rightText) {
        mTitleBar.setRightText(rightText);
    }

    public void setTitleBarLeftVisibility(@Visibility int visibility) {
        mTitleBar.setLeftVisibility(visibility);
    }

    public void setTitleBarRight(String rightText, int iconId, boolean iconAtLeft) {
        mTitleBar.setRightTextAndIcon(rightText, iconId, iconAtLeft);
    }

    public void setTitleBarLeft(String leftText, int iconId, boolean iconAtLeft) {
        mTitleBar.setLeftTextAndIcon(leftText, iconId, iconAtLeft);
    }

    public void setTitleBarRightVisibility(@Visibility int visibility) {
        mTitleBar.setRightVisibility(visibility);
    }

    public void setTitleBarLeftClick(View.OnClickListener onLeftClickListener) {
        mTitleBar.setTitleBarLeftClick(onLeftClickListener);
    }

    public void setTitleBarRightClick(View.OnClickListener onRightClickListener) {
        mTitleBar.setTitleBarRightClick(onRightClickListener);
    }

    public void setTitleBarRightFirstClick(View.OnClickListener onRightClickListener) {
        mTitleBar.setTitleBarRightFirstClick(onRightClickListener);
    }

    public void setTitleBarRightFirstVisibility(@Visibility int visibility) {
        mTitleBar.setRightFirstVisibility(visibility);
    }

    public void setTitleBarRightFirst(int drawable) {
        mTitleBar.setRightFirstDrawable(drawable);
    }

    public void setTitleBarTitleClick(View.OnClickListener onTitleClickListener) {
        mTitleBar.setTitleBarTitleClick(onTitleClickListener);
    }
}
